<%
  scope ||= nil
  subsection_id ||= nil
  tab_value ||= nil
  tabbed_by ||= nil
  tab_id ||= nil
  show_unauthorized_columns = active_scaffold_config.send(form_action).show_unauthorized_columns if active_scaffold_config.actions.include? form_action
%>
<ol class="form" <%= "id=#{subsection_id}" unless subsection_id.nil? %> <%= 'style="display: none;"'.html_safe if columns.collapsed %>>
  <% columns.each_column(for: @record, crud_type: (:read if show_unauthorized_columns)) do |column| %>
  <% column_css_class = column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc) %>
  <% renders_as = column_renders_as(column) %>
  <% authorized = show_unauthorized_columns || renders_as == :subsection ? @record.authorized_for?(crud_type: form_action, column: column.name) : true %>
  <% if renders_as == :subsection -%>
    <% next unless authorized %>
  <li class="sub-section <%= column_css_class %>">
    <%= render_subsection(column, @record, scope, form_action) %>
  </li>
  <% elsif renders_as == :subform && (authorized || column.show_ui) -%>
    <%
      subform_attrs = active_scaffold_subform_attributes(column, column_css_class, tab_id: tab_id)
      subform_attrs[:class] = "#{subform_attrs[:class]} read-only".strip unless authorized
      tab_options = local_assigns.slice(:tabbed_by, :tab_id, :tab_value)
      tab_options[:tabbed_by] = column.options[:tabbed_by] if tabbed_by && column.options[:tabbed_by]
    %>
  <%= content_tag :li, subform_attrs do %>
    <% if authorized %>
    <%= render_column(column, @record, renders_as, scope, **tab_options) %>
    <% else %>
    <%= show_column_value(@record, column, **tab_options) %>
    <% end %>
  <% end %>
  <% else -%>
  <li class="form-element <%= 'required' if column.required?(action_for_validation(@record)) %> <%= column.form_ui %> <%= column_css_class %>">
    <%= render_column(column, @record, renders_as, scope, only_value: !authorized) %>
  </li>
  <% end -%>
  <% end -%>
</ol>
